<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>退货订单收货入库 - [[${T(com.b2c.erp.DataConfigObject).getInstance().getSysName()}]]</title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;top: 0px;">

    <!-- start sp-wrapper -->
    <link rel="stylesheet" href="/sb/stock.css"/>
    <fieldset class="layui-elem-field">
        <legend>单号搜索(支持拼多多、淘宝)</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane1" method="get" action="/order_return/receiving">
                <div class="layui-form-item">

                    <div class="layui-inline">
                        <input type="text" name="num" placeholder="物流单号、订单号、退货单号" th:value="${num}" class="layui-input" style="width: 260px;">
                    </div>
                    <!-- <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="shopType" id="shopType">
                                <option value="">网店平台</option>
                                <option value="5" >拼多多</option>
                                <option value="4" >淘系</option>
                                <option value="6">抖音</option>
                                <option value="99" >ERP系统</option>

                            </select>
                        </div>
                    </div> -->
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn">查询</button>
                        <i>总共：&nbsp;[[${totalSize}]]&nbsp;条记录</i>
                    </div>
                    <div class="layui-inline"></div>

                </div>
            </form>



        </div>
    </fieldset>
    <div class="sp-wrapper">
        <h2 class="sp-title"><span>退货订单详情(<i th:text="${totalSize}" style="color: red"></i>)</span></h2>

        <div class="sp-table">
            <table>
                <thead>
                <tr>
                    <th width="160px">单号</th>
                 
                    <th width="100px">店铺</th>
                    <th>图片</th>
                    <th>商品</th>
                    <th>规格</th>
                    <th>sku</th>
                    <th width="30px">数量</th>
                    <th width="50px">售后类型</th>
                    <th>创建时间</th>
                    <th>收货物流信息</th>
                    <th width="150px">备注</th>
                    <th width="100px">状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="sp-data">
                <tr th:if="${totalSize == 0}">
                    <td colspan="11" align="center" style="vertical-align:middle; text-align:center;color: red;" ><h1>没有找到数据，是不是没有拉取到最新的退货订单，请更新拼多多、淘宝店铺退货订单</h1></td>
                </tr>
                <tr th:each="item:${list}">
                    <td >
                        <b th:text="${item.refundId}"></b>
                        <br />
                        <b th:text="${item.orderSn}"></b>
                    </td>
                   
                    <td >
                        <b th:if="${item.shopType == 4}" style="color: rgb(74, 11, 212);" > <img src="https://img.alicdn.com/tps/i3/T1OjaVFl4dXXa.JOZB-114-114.png" style="width: 20px;height:20px"/></b>
                        <b th:if="${item.shopType == 5}" style="color: rgb(74, 11, 212);" ><img src="https://mms-static.pddpic.com/express/favicon.ico" style="width: 20px;height:20px"/></b>
                        <b th:if="${item.shopType == 6}" style="color: rgb(74, 11, 212);" ><img src="https://lf1-fe.ecombdstatic.com/obj/eden-cn/upqphj/homepage/icon.svg" style="width: 20px;height:20px"/></b>
                        <b th:text="${item.shopName}"></b><br/>
                        
                        <i th:if="${item.shopType == 5}">拼多多</i>
                        <i th:if="${item.shopType == 4}">淘宝</i>
                        <i th:if="${item.shopType == 6}">抖店</i>
                    </td>
                    <td >
                        <img th:src="${item.goodsImage}" style="width: 50px;height: 50px;">
  
                    </td>
                    <td >
                        <b th:text="${#strings.abbreviate(item.goodsName,18)}" th:title="${item.goodsName}"></b> 
                    </td>
                    <td><b th:text="${item.skuName}"></b></td>
                    <td th:text="${item.skuNumber}"></td>
                    <td th:text="${item.quantity}"></td>
                    <td >
                        <div th:if="${item.shopType == 5}">
                            <!---pdd--->
                            <b style="color: red;" th:if="${item.afterSalesType == 2}">仅退款</b>
                            <b style="color: red;" th:if="${item.afterSalesType == 3}">退货退款</b>
                            <b style="color: red;" th:if="${item.afterSalesType == 4}">换货</b>
                            <b style="color: red;" th:if="${item.afterSalesType == 5}">缺货补寄</b>
                            <b style="color: red;" th:if="${item.afterSalesType == 9}">拦截退货</b>
                        </div>
                        <div th:if="${item.shopType == 6}">
                            <b style="color: red;" th:if="${item.afterSalesType == 0}">退货退款</b>
                            <b style="color: red;" th:if="${item.afterSalesType == 9}">拦截退货</b>
                        </div>
                    </td>


                    <td th:text="${#dates.format(item.createdTime * 1000, 'yyyy-MM-dd HH:mm:ss')}">XS201903260932042</td>
                    <td >
                    
                    <b th:text="${item.trackingNumber}"></b><br/>
                    <b th:text="${item.trackingCompany}"></b>
                    </td>
                    <td >
                        <b th:text="${item.remark}"></b>
                        <span th:attr="refund-id=${item.refundId},remark=${item.remark},shopId=${item.shopId}" title="备注" class="sellerRemark">
                            <i class="layui-icon layui-icon-note"></i>
                        </span>
                    </td>
                    <td>
                        <b th:if="${item.shopType == 5}" th:text="${T(com.b2c.entity.pdd.EnumPddOrderRefundStatus).getName(item.afterSalesStatus)}"></b>
                        <b th:if="${item.shopType == 6}" th:text="${T(com.b2c.entity.enums.third.EnumDouYinOrderRefundStatus).getName(item.afterSalesStatus)}"></b>
                        <b th:if="${item.shopType == 4}" th:text="${T(com.b2c.entity.enums.tao.EnumDcTmallOrderReturnStatus).getName(item.afterSalesStatus)}"></b>
                       
                        <br />
                        <b th:if="${item.auditStatus==0}" style="color: rgb(21, 205, 222);">未处理</b>
                        <b th:if="${item.auditStatus==2}" style="color: rgb(37, 204, 45);">已签收待处理</b>
                        <b th:if="${item.auditStatus==9}" style="color: red;">供应商已退款</b>
                        <b th:if="${item.auditStatus==10}" style="color: red;">换货已完成</b>
                        <b th:if="${item.auditStatus==99}" style="color: rgba(90, 90, 90, 0.771);">已关闭</b>
                        <b th:if="${item.auditStatus==91}" style="color: rgba(90, 90, 90, 0.771);">等待财务处理</b>
                        <b th:if="${item.auditStatus==100}" style="color: rgba(90, 90, 90, 0.771);">计入损失</b> 
                    </td>

                    <td>
                        <!-- <a class="view confirmReceive2" target="_blank" th:if="${not #strings.isEmpty(item.refundId) && item.orderId==0 && (item.shopId == 5 || item.shopId == 18)}" th:href="@{/order_return/receiving_refund_shop(id=${item.refundId})}" >确认收货</a>
                        <a class="view confirmReceive2 hbdb"  th:if="${not #strings.isEmpty(item.refundId) && item.orderId==0 && (item.shopId == 5 || item.shopId == 18) }" href="javascript:;" >货不对版</a> -->

                        <a th:attr="refund-id=${item.refundId},trackcode=${item.trackingNumber},shopId=${item.shopId},goodsName=${item.goodsName},typeName=${item.typeName},skuNumber=${item.skuNumber},remark=${item.remark}" href="javascript:;" title="加入代办列表" class="addtodo">
                            <i class="layui-icon layui-icon-log"></i>
                        </a>
                        <br />
                        <a th:if="${item.auditStatus==0  }" class="layui-btn-sm layui-btn-primary layui-btn-radius receive_confirm"  th:attr="data-id=${item.refundId},shopId=${item.shopId}" href="javascript:;">签收</a>

                        <a th:if="${item.auditStatus==2  }" title="标记为已退款" class="sign_refund"  th:attr="data-id=${item.refundId},shopId=${item.shopId},auditStatus=9" href="javascript:;">
                            <i class="layui-icon layui-icon-rmb"></i>
                        </a>
                    </td>
                </tr>
                </tbody>
            </table>
            <div class="pages">
                <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
            </div>
        </div>
    </div>


    <script type="text/javascript" src="/sb/jquery.min.js"></script>
    <script type="text/javascript" src="/sb/Tips.min.js"></script>
    <script type="text/javascript">
        $(function () {

            function getDateTime(timestamp) {
                var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
                var Y = date.getFullYear();
                var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
                var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
                var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours());
                var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
                var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
                return Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s;
            }
        });
    </script>
    <!-- end sp-wrapper -->
    <script>
        layui.use(['laydate', 'layer','form'], function () {
            var laydate = layui.laydate;
            var layer = layui.layer;
            var form = layui.form;
            $("#shopType").val([[${shopType}]]);
            form.render('select'); //刷新select选择框渲染

            $(function () {
                //加入代办
            $(".addtodo").click(function(){
                var refundId = $(this).attr('refund-id');
                var shopId = $(this).attr('shopId');
                var remark = $(this).attr('remark');
                if(remark == ''||remark==null) remark = "退货";
                var skuNumber = $(this).attr("skuNumber");
                var typeName = $(this).attr('typeName');
                var trackcode = $(this).attr('trackcode');
                if(trackcode == undefined) trackcode='';
                else trackcode += "";
                var goodsName = $(this).attr('goodsName');
                var obj = $(this).siblings('b').eq(0);

                layer.prompt({
                    formType: 2,
                    value: typeName+remark+'：'+trackcode+"（"+skuNumber+"）",
                    title: '代办内容'
                }, function(value, index, elem){
                    var data = {sourceType:1,sourceId:refundId,shopId:shopId, content:value};
                    $.ajax({
                        url: "/ajax_todo/add_todo",
                        type: "POST",
                        dataType: "JSON",
                        contentType: 'application/json',
                        data:JSON.stringify(data),
                        success: function (res) {

                            if(res.code == 0){

                                $(obj).text(value);
                                layer.close(index)
                                layer.msg(res.msg);
                                // location=location;
                            }else
                                layer.alert(res.msg);
                        }
                    });


                });
            }); 

            //备注
            $(".sellerRemark").click(function(){
                var refundId = $(this).attr('refund-id');
                var remark = $(this).attr('remark');
                let shopId = $(this).attr('shopId');

                var obj = $(this).siblings('b').eq(0);

                layer.prompt({
                    formType: 2,
                    value: remark,
                    title: '请输入备注'
                }, function(value, index, elem){
                    var data = {refundId:refundId, remark:value,shopId:shopId};
                    $.ajax({
                        url: "/order_return/refund_remark_updata",
                        type: "POST",
                        dataType: "JSON",
                        contentType: 'application/json',
                        data:JSON.stringify(data),
                        success: function (res) {

                            if(res.code == 0){

                                $(obj).text(value);
                                layer.close(index)
                                layer.msg(res.msg);
                                // location=location;
                            }else
                                layer.alert(res.msg);
                        }
                    });


                });
            });

            //标记为退款
            $(".sign_refund").click(function () {
                var $this = $(this);
                let refId = $(this).attr('data-id');
                let auditStatus = $(this).attr('auditStatus');
                let shopId = $(this).attr('shopId');

                if(confirm("该操作不可逆，是否确定要标记为已处理？")){
                    var data = {
                        id: refId,
                        auditStatus:auditStatus,
                        shopId:shopId
                    };
                    $.ajax({
                        url: "/order_return/sign_refund",
                        type: "POST",
                        dataType: 'json',
                        contentType: 'application/json',
                        data: JSON.stringify(data),
                        success: function (res) {
                            if (res.code == 0) {
                               layer.msg("处理成功");
                                //$this.parent().parent().remove();
                               window.location.reload();
                            } else {
                                alert(res.msg);
                                return false;
                            }
                        }
                    });
                }
            })

            //标记为已签收
            $(".receive_confirm").click(function () {
                var $this = $(this);
                let refId = $(this).attr('data-id');
                let shopId = $(this).attr('shopId');
                

                if(confirm("该操作不可逆，是否确定要标记为已处理？")){
                    var data = {
                        id: refId,
                        shopId:shopId
                    };
                    $.ajax({
                        url: "/order_return/refund_receive_confirm",
                        type: "POST",
                        dataType: 'json',
                        contentType: 'application/json',
                        data: JSON.stringify(data),
                        success: function (res) {
                            if (res.code == 0) {
                               layer.msg("处理成功");
                                //$this.parent().parent().remove();
                               window.location.reload();
                            } else {
                                alert(res.msg);
                                return false;
                            }
                        }
                    });
                }

            })




            });
        })

    </script>
</div>
</body>
<html>
